<?php

/*
 * @author Ebrain Cedeno <ebraincedeno@gmail.com>
 */

class TWidget{
    
    public $Name;
    public $Id;
    public $Top = 0;
    public $Left = 0;
    public $Height=25;
    public $Width=100;
    public $Visible = true;
    public $OptionsAditional = array();
    
    public function __construct($name=__CLASS__) {
        $this->Name = $name."_".rand(1, 1000);
        $this->Id = $this->Name;
    }
    
    public function showJs(){
        ?>
<script type="text/javascript">
        <?php
        if ($this->Visible == false){
            ?>
                document.getElementById('<?php echo $this->Id; ?>').style.visibility = 'visible';
                document.getElementById('<?php echo $this->Id; ?>').style.display = 'inline';
            <?php
        }
        ?>
</script>
        <?php
    }
    
    public function hideJs(){
        ?>
<script type="text/javascript">
        <?php
        if ($this->Visible == false){
            ?>
                document.getElementById(<?php echo $this->Id; ?>).style.visibility = 'hidden';
                document.getElementById(<?php echo $this->Id; ?>).style.display = 'none';
            <?php
        }
        ?>
</script>
        <?php
    }
    
    public function getOptionsAditional(){
        
        if (array_key_exists('style',$this->OptionsAditional)){
            if (is_array($this->OptionsAditional)){
                $array_aditional = array();
                if ($this->Top > 0){
                    $array_aditional[] = 'top:'.$this->Top.'px;';
                }
                
                if ($this->Left > 0){
                    $array_aditional[] = 'left:'.$this->Left.'px;';
                }
                
                if (count($array_aditional) > 0){
                    $this->OptionsAditional['style'] = array_merge($this->OptionsAditional['style'],$array_aditional);
                }
            }
        }
        
        if (count($this->OptionsAditional) > 0){
            $Aditional = '';
            foreach ($this->OptionsAditional as $llave=>$value){
                if (is_array($value)){
                    if (strtolower($llave) == "style"){
                        $Aditional .= ' style="';
                        foreach ($value as $key=>$valor){
                            $Aditional .= $valor.'; ';
                        }
                        $Aditional .= '"';
                    }
                }
                else{
                    $Aditional .= ' '.$llave.'="'.$value.'"';
                }
            }
            
        }else{
            $Aditional = '';
        }
        
        return $Aditional;
        
    }
}

?>
